<!DOCTYPE html>
<html lang="en">
  	<head>
	    <meta charset="utf-8">
	    <title>学生管理系统</title>
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <meta name="description" content="">
	    <meta name="author" content="">

	    <!-- Bootstrap core CSS -->
	    <link href="/admin/bootstrap/css/bootstrap.min.css" rel="stylesheet">
		
		<!-- Font Awesome -->
		<link href="/admin/css/font-awesome.min.css" rel="stylesheet">

		<!-- ionicons -->
		<link href="/admin/css/ionicons.min.css" rel="stylesheet">
		
		<!-- Simplify -->
		<link href="/admin/css/simplify.min.css" rel="stylesheet">
	
  	</head>

  	<body class="overflow-hidden light-background">
		<div class="wrapper no-navigation preload">
			<div class="sign-in-wrapper">
				<div class="sign-in-inner">
					<div class="login-brand text-center">
						<i class="fa fa-database m-right-xs"></i> 学生 <strong class="text-skin">管理系统</strong>
					</div>

					<form method="post" id="regForm">
						<div class="form-group m-bottom-md">
							<input type="email" name="email" class="form-control" placeholder="请输入邮箱">
						</div>
						<div class="form-group">
							<input type="password" name="pwd" class="form-control" placeholder="请输入密码">
						</div>
						<div class="form-group">
							<input type="password" name="pwd2" class="form-control" placeholder="请确认密码">
						</div>
						<div class="form-group">
							<input type="text" name='code' class="form-control pull-left" style="width: 200px;" placeholder="请确认验证码">
							<button type="button" id='sendCode' class="btn btn-success block pull-right">发送验证码</button>
							<div class="clearfix"></div>
						</div>
						<div class="form-group">
							<div class="custom-checkbox">
								<input type="checkbox" id="chkAccept" name="agree">
								<label for="chkAccept"></label>
							</div>
							我同意该协议《<a href="">学生管理协议</a>》
						</div>

						<div class="m-top-md p-top-sm">
							<a href="javascript:;" class="btn btn-success block" id="reg">立即注册</a>
						</div>

						<div class="m-top-md p-top-sm">
							<div class="font-12 text-center m-bottom-xs">我已有账号?</div>
							<a href="/admin/main/login" class="btn btn-default block">登录</a>
						</div>
					</form>
				</div><!-- ./sign-in-inner -->
			</div><!-- ./sign-in-wrapper -->
		</div><!-- /wrapper -->

		<a href="" id="scroll-to-top" class="hidden-print"><i class="icon-chevron-up"></i></a>

	    <!-- Le javascript
	    ================================================== -->
	    <!-- Placed at the end of the document so the pages load faster -->
		
		<!-- Jquery -->
		<script src="/admin/js/jquery-1.11.1.min.js"></script>
		
		<!-- Bootstrap -->
	    <script src="/admin/bootstrap/js/bootstrap.min.js"></script>
		
		<!-- Slimscroll -->
		<script src='/admin/js/jquery.slimscroll.min.js'></script>
		
		<!-- Popup Overlay -->
		<script src='/admin/js/jquery.popupoverlay.min.js'></script>

		<!-- Modernizr -->
		<script src='/admin/js/modernizr.min.js'></script>
		
		<!-- Simplify -->
		<script src="/admin/js/simplify/simplify.js"></script>

		<!-- 验证函数 -->
		<script src="/admin/js/common.js"></script>
		
		<script>
			//发送验证码
			$('#sendCode').on('click',function(){
				var _this = this
				$(_this).addClass('').removeClass('btn-success')
				var num = 60
				var sendTime = setInterval(function(){
						num --
						// console.log(num);
						$(_this).html(num+'s后重新发送')//此次的this是定时器不能使用$(this) 除非给this定义
						
					},1000)

				setTimeout(function(){
					clearInterval(sendTime)
					$(_this).addClass('btn-success').removeClass('btn-default disabled').html('发送验证码')
				},60000)
			
				// <i class="fa fa-spinner fa-spin m-right-xs"></i>
				//获取输入的邮箱
				var email = $("[name='email']").val()
				//判断邮箱是否填写
				if(!checkEmail(email)){
					alert('请正确输入邮箱');
					return false;
				}

				//ajax结构
				$.ajax({
					url: '/admin/main/sendCode',
					type:'post',
					data:{email:email},
					dataType:'json',	// 回调的数据类型
					success:function(res){
					}
				});

			})


			// 注册页面，写ajax提交操作
			$('#reg').on('click',function(){
				var formdata = new FormData($('#regForm')[0]);  // 括号是js表单对象
				if(!checkEmail(formdata.get('email'))){
					alert('请正确输入邮箱');
					return false;
				}
				if(checkRequired(formdata.get('pwd'))){
					alert('请输入密码');
					return false;
				}
				if(formdata.get('pwd')!=formdata.get('pwd2')){
					alert('密码不一致');
					return false;
				}
				if(formdata.get('agree')==undefined){
					alert('请勾选同意协议');
					return false;
				}
				$.ajax({
					url: '/admin/main/registerData',
					type:'post',
					data:formdata,
					contentType: false,
        			processData: false,
					dataType:'json',	// 回调的数据类型
					success:function(res){
						alert(res.msg);
						if(res.error==0){
							//跳转到登录页
							location.href = '/admin/main/login';
						}
					}
				});
			});
			
		</script>
  	</body>
</html>
